<?php

namespace App\Models;

use App\Services\WxMp\WxMpListService;
use App\Services\WxMp\WxMpPayListService;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * 微信应用列表
 * @package App\Models
 */
class WxMpList extends Model
{
    use SoftDeletes;

    //主键
    protected $primaryKey = 'id';
    protected $dateFormat = 'Y-m-d H:i:s';
    protected $dates = [
    ];
    /**
     * 追加到模型数组表单的访问器。
     *
     * @var array
     */
    protected $appends = ['type_name'];
    /**
     * 不可批量赋值的属性。
     *
     * @var array
     */
    protected $guarded = [];

    /**
     * 应该被转换成原生类型的属性。
     * @var array
     */
    protected $casts = [
    ];

    /**
     * 应用类别名称
     * @param $value
     * @return mixed|string
     */
    public function getTypeNameAttribute($value)
    {
        $type = $this->type;
        $typeConf = [
            WxMpListService::TYPE_WECHAT => '公众号',
            WxMpListService::TYPE_APPLET => '小程序',
            WxMpListService::TYPE_OPEN_PLATFORM => '开放平台',
            WxMpListService::TYPE_PAYMENT => '微信支付',
        ];
        return isset($typeConf[$type]) ? $typeConf[$type] : '';
    }
    /**
     * 关联开放平台授权应用信息
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function openAuthorizer()
    {
        return $this->hasOne('App\Models\WxMpOpenAuthorizer','appid', 'appid');
    }
}
